package com.summer.ChengXuYuanMianShiJingDian;
import  com.summer.ListNode;
public class Q2_6 {
//    输入： 1->2->2->1
//    输出： true
public static void main(String[] args) {
    ListNode node = new ListNode(-129);
    ListNode node1 = new ListNode(-129);
    node.next=node1;
    System.out.println(isPalindrome(node));
}
    public static boolean isPalindrome(ListNode head) {
        if (head==null||head.next==null)return true;
        ListNode cur = head;
        int count = 0;
        while (cur!=null){
            count++;
            cur = cur.next;
        }
       int[] arr = new int[count];
        int i = 0;
        while (head!=null&&i<count){
            arr[i++]= head.val;
            head = head.next;
        }
        boolean flag = true;
        int l = count-1;
        for (int j = 0; j <count&&j<=l ; j++) {
            if (arr[j]!=arr[l]){
                flag=false;
                break;
            }
            l--;

        }
    return flag;
    }
}
